Thumb

JavaScript Arrays

1/21/2020 7:13:20 AM

JavaScript array is a single variable for multipole value store. The array is zero base. When we create the array then the value starts from zero index. When we create an array, we use new keyword or without new keyword. Array can store varies type of data. Now given bellow the example code and explain the code:

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>

<script type="text/javascript">
	//with out new keyword
var fruits = ["Banana", "Orange", "Apple", "Mango"];
for (var i =0; i <=  fruits.length; i++) {
	console.log(fruits[i]);
	}
//using new keyword
	var name = new Array("Jesy", "Reza", "Tofile");
for (var i =0; i <=  cars.length; i++) {
	console.log(cars[i]);
	}
</script>

</body>
</html>

First, we create an array name as fruits. Then assign the value using “[]”. All value is string type because we use the double quotation. Then print the value using for loop. Then we write another array name as “name” this value stores the string value. We use the value using “new” keyword also use “()” first bracket symbol.